<template>
	<view>
		<uni-nav-bar @clickLeft	="back" leftIcon="left" statusBar title="我的优惠券" fixed></uni-nav-bar>
		<view class="school-coupon" >
	     	<view class="tab flex" >
				<view class="tab_item text-df text-bold" :class="tab_index == 1 ? 'active' : ''" @click="tab_index = 1">待使用</view>
				<view class="tab_item text-df text-bold" :class="tab_index == 2 ? 'active' : ''" @click="tab_index = 2">已使用</view>
				<view class="tab_item text-df text-bold" :class="tab_index == 3 ? 'active' : ''" @click="tab_index = 3">已过期</view>
			</view>
			<!-- <view style="height:80vh;"></view> -->
			<view class="padding">
				<block v-for="(item, index) in dataList" :key="index">
					<view class="coupon" :class="'sty'+ tab_index">
						<view class="row">
							<view class="tag">{{ item.store_id ? "商家券" : "平台券" }}</view>
							<view class="price row">
								<view class="key">￥</view>
								<!-- {{ item.cut_num }} -->
								{{ item.price }}
							</view>
							<view class="flex-col">
								<view class="name">{{ item.c_name }}</view>
								<view class="tips">全场商品通用，不可叠加</view>
							</view>
							<!-- v-if="item.is_have==0" -->
							<!-- {{ item.u_cont }}||{{ item.second } -->
							<block v-if="item.store_id">
							
								<view class="btns row" v-if="tab_index==1" @click="goStore(item.store_id)" >去使用</view>

								<view class="btns row" style="background: gray;" v-else>无法使用</view>
							</block>
						
						</view>
						<view class="store_name" v-if="item.store_id">
							{{ item.business.business_name }}
						</view>
					</view>
				</block>



			</view>

            
	    </view>

		<school-coupon class="aaa"></school-coupon>
	</view>
</template>

<script>
import uninavbar from '../../components/uni-nav-bar/uni-nav-bar.vue';
import uninavbar2 from '../../components/uni-data-checkbox/components/uni-data-checkbox/uni-data-checkbox.vue';
import main from "@/middleware/main"
export default {
	components: {
		"uni-nav-bar": uninavbar,
		"uni-data-checkbox": uninavbar2,

	},
	data() {
		return {
			page:1,
			dataList:[],
			tab_index:1
		};
	},
	watch:{
		tab_index(){
			this.page=1
			this.initData()
		}
	},
	onLoad(options) {
		this.initData()
	},
	// 页面处理函数--监听用户下拉动作
	// onPullDownRefresh() { uni.stopPullDownRefresh(); },
	// 页面处理函数--监听用户上拉触底
	onReachBottom() {
		this.page+=1
		this.initData()
	},
	methods:{
		initData(){
			this.request("UserCoupon/user_coupon", {
				page:this.page,
				state:this.tab_index
			}).then(res=>{

				this.dataList= this.page==1?res.data.data.list:[
					...this.dataList,
					...res.data.data.list
				]
			})
		},
		back(){
			uni.navigateBack({ delta: 1 })
		},
		goStore(bid){
			uni.navigateTo({ url: '/gc_school/pages/foold/foold?id='+bid })
		}
	}
}
</script>

<style lang="scss">
	@import "./main.scss";
</style>
